Imports System.Data.Common
Partial Class Presentation_Change_Details
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Page.Title = "Modifying Screen"


    End Sub

    Protected Sub rlEditChoice_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rlEditChoice.SelectedIndexChanged

        Dim First As New ListItem

        lblEnterPart.Visible = True

        Select Case rlEditChoice.SelectedValue

            Case "Client"
                lblEnterPart.Text = "Please enter a part of the Client's Name"
                btnSubmit.PostBackUrl = "~/Presentation/CreateCompany.aspx"

            Case "Contact"
                lblEnterPart.Text = "Please enter a part of the Contact's Name"
                btnSubmit.PostBackUrl = "~/Presentation/ContactEntry.aspx"

        End Select

        txtEnterPart.Visible = True
        dlChoices.Visible = True
        btnSubmit.Visible = True

        dlChoices.Items.Clear()
        First.Text = "Make a choice"
        First.Value = "0"
        First.Selected = True
        If Not dlChoices.Items.Contains(First) Then
            dlChoices.Items.Add(First)
        End If



    End Sub

    Protected Sub txtEnterPart_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtEnterPart.TextChanged

        Dim Sql As String
        Dim Params(0) As GenParameter
        Dim First As New ListItem

        Select Case rlEditChoice.SelectedValue

            Case "Client"

                Sql = "Select CompanyAssignments.ClientID AS 'ClientID', ClientMaster.ClientName AS 'ClientName' from CompanyAssignments INNER JOIN ClientMaster" & _
                    " ON ClientMaster.ClientID = CompanyAssignments.ClientID" & _
                    " WHERE ClientMaster.ClientName LIKE CONCAT('%',?ClientName,'%') AND CompanyAssignments.ExecutiveID = " & Request.Cookies("Profile").Item("ExecutiveID") & _
                    " ORDER BY ClientMaster.ClientName"

                Params(0) = New GenParameter("?ClientName", txtEnterPart.Text, Data.DbType.String)

                dlChoices.DataTextField = "ClientName"
                dlChoices.DataValueField = "ClientID"

            Case Else

                Sql = "SELECT ContactMaster.ContactID, ContactMaster.ContactName" & _
                        " FROM ((ClientMaster INNER JOIN CompanyAssignments ON ClientMaster.ClientID = CompanyAssignments.ClientID) INNER JOIN ExecutiveMaster ON CompanyAssignments.ExecutiveID = ExecutiveMaster.ExecutiveID) INNER JOIN ContactMaster ON ClientMaster.ClientID = ContactMaster.ClientID" & _
                        " WHERE CompanyAssignments.ExecutiveID = " & Request.Cookies("Profile").Item("ExecutiveID") & _
                        " AND ContactMaster.ContactName LIKE CONCAT('%',?ContactName,'%')"

                Params(0) = New GenParameter("?ContactName", txtEnterPart.Text, Data.DbType.String)

                dlChoices.DataTextField = "ContactName"
                dlChoices.DataValueField = "ContactID"


        End Select

        dlChoices.Items.Clear()
        dlChoices.DataSource = GenHelper.ExecuteReader(Sql, Params, ConfigurationManager.ConnectionStrings.Item("MySqlConnString").ToString())
        dlChoices.DataBind()
        First.Text = "Make a choice"
        First.Value = "0"
        First.Selected = True
        dlChoices.Items.Add(First)

    End Sub

    'Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click

    '    If Not Page.IsValid Then
    '        Return
    '    End If

    '    Select Case rlEditChoice.SelectedValue

    '        Case "Client"
    '            Server.Transfer("~/Presentation/CreateCompany.aspx")

    '        Case "Contact"
    '            Server.Transfer("~/Presentation/ContactEntry.aspx")
    '    End Select


    'End Sub

    Public ReadOnly Property GetUniqueID() As Integer
        Get
            Return dlChoices.SelectedValue
        End Get
    End Property

End Class
